//package site.wattsnwc.aspect;
//
//import com.mongodb.BasicDBObject;
//import org.apache.log4j.Logger;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Before;
//import org.aspectj.lang.annotation.Pointcut;
//import org.springframework.core.annotation.Order;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.servlet.http.HttpServletRequest;
//import java.util.Arrays;
//import java.util.Enumeration;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * Web层日志切面
// *
// * @author 程序猿DD
// * @version 1.0.0
// * @date 16/5/17 上午10:42.
// * @blog http://blog.didispace.com
// */
//@Aspect
//@Order(1)
//@Component
//public class WebLogAspect {
//
//    private Logger logger = Logger.getLogger("mongodb");
//
//    @Pointcut("execution(public * site.wattsnwc.controller..*.*(..))")
//    public void webLog(){}
//
//    @Before("webLog()")
//    public void doBefore(JoinPoint joinPoint) throws Throwable {
//        // 获取HttpServletRequest
//        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        HttpServletRequest request = attributes.getRequest();
//        // 获取要记录的日志内容
//        BasicDBObject logInfo = getBasicDBObject(request, joinPoint);
//        logger.info(logInfo);
//    }
//
//
//    private BasicDBObject getBasicDBObject(HttpServletRequest request, JoinPoint joinPoint) {
//        // 基本信息
//        BasicDBObject r = new BasicDBObject();
//        r.append("requestURL", request.getRequestURL().toString());
//        r.append("requestURI", request.getRequestURI());
//        r.append("queryString", request.getQueryString());
//        r.append("remoteAddr", request.getRemoteAddr());
//        r.append("remoteHost", request.getRemoteHost());
//        r.append("remotePort", request.getRemotePort());
//        r.append("localAddr", request.getLocalAddr());
//        r.append("localName", request.getLocalName());
//        r.append("method", request.getMethod());
//        r.append("headers", getHeadersInfo(request));
//        r.append("parameters", request.getParameterMap());
//        r.append("classMethod", joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
//        r.append("args", Arrays.toString(joinPoint.getArgs()));
//        return r;
//    }
//
//    /**
//     * 获取头信息
//     *
//     * @param request
//     * @return
//     */
//    private Map<String, String> getHeadersInfo(HttpServletRequest request) {
//        Map<String, String> map = new HashMap<>();
//        Enumeration headerNames = request.getHeaderNames();
//        while (headerNames.hasMoreElements()) {
//            String key = (String) headerNames.nextElement();
//            String value = request.getHeader(key);
//            map.put(key, value);
//        }
//        return map;
//    }
//
//}
//
